package ${package.Controller};


import org.springframework.web.bind.annotation.*;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import com.lahuan.common.Result;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${table.entityName};
import javax.validation.Valid;
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 控制器
 * </p>
 * @author ${author}
 * @since ${date}
 */
@RequiredArgsConstructor
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@Slf4j
@Api(value = "${table.name}", tags = "${table.comment}接口")
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    private final ${table.serviceName} ${table.serviceName?uncap_first};

    @ApiOperation(value = "获取${table.comment}分页列表",notes="获取${table.comment}分页列表")
    @GetMapping("")
    public  Result<Page<${table.entityName}>> ${table.entityName?uncap_first}List(Page< ${table.entityName}> page, ${table.entityName} query) {
        return Result.ok(${table.serviceName?uncap_first}.page(page, Wrappers.query(query)));
    }

    @ApiOperation(value = "根据id获取${table.comment}",notes="根据id获取${table.comment}")
    @ApiImplicitParam(name = "id", value = "${table.comment}id", required = true, dataType = "<#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> ")
    @GetMapping("/{id}")
    public Result<${table.entityName}> ${table.entityName?uncap_first}GetById(@PathVariable <#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> id) {
        return Result.ok(${table.serviceName?uncap_first}.getById(id));
    }

    @ApiOperation(value = "添加${table.comment}",notes="新增${table.comment}")
    @PostMapping("")
    public Result<Boolean> ${table.entityName?uncap_first}Save(@RequestBody @Valid  ${table.entityName} ${table.entityName?uncap_first}) {
        return Result.ok(${table.serviceName?uncap_first}.save(${table.entityName?uncap_first}));
    }

    @ApiOperation(value = "修改${table.comment}",notes="根据id修改${table.comment}")
    @PutMapping("/{id}")
    public Result<Boolean> ${table.entityName?uncap_first}Update(@RequestBody @Valid  ${table.entityName} ${table.entityName?uncap_first}, @PathVariable <#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> id) {
        ${table.entityName?uncap_first}.setId(id);
        return Result.ok(${table.serviceName?uncap_first}.updateById(${table.entityName?uncap_first}));
    }

    @ApiOperation(value = "删除${table.comment}",notes="根据id删除${table.comment}")
    @ApiImplicitParam(name = "id", value = "${table.comment}id", required = true, dataType = "<#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> ")
    @DeleteMapping("/{id}")
    public Result<Boolean> ${table.entityName?uncap_first}Delete(@PathVariable <#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> id) {
        return Result.ok(${table.serviceName?uncap_first}.removeById(id));
    }


}
</#if>
